#ifndef _SENSOR_ULTRASONIC_H
#define	_SENSOR_ULTRASONIC_H

#include "main.h"
#include "math.h"
#include "tim.h"
#include "Delay.h"
#include "UART/uart_app.h"

/**
 ****************************************************************************************************
 * DONE 用户变量区
 ****************************************************************************************************
 */

#define 	ULTRASONIC_TRIG_GPIO_PORT					GPIOB
#define 	ULTRASONIC_ECHO_GPIO_PORT					GPIOC
#define 	ULTRASONIC_TRIG_GPIO_PIN					GPIO_PIN_14	
#define 	ULTRASONIC_ECHO_GPIO_PIN					GPIO_PIN_6	

//-----------------------------------------------	

extern uint16_t msHcCount;

/**
 ****************************************************************************************************
 * DONE 用户函数
 ****************************************************************************************************
 */

/** 
 * @if Eng
 * @brief Initializes the ultrasonic sensor hardware 
 * @param None
 * @result Ultrasonic sensor is ready for distance measurement
 * @else
 * @brief 初始化超声波传感器硬件 
 * @param 无 
 * @result 超声波传感器准备就绪可进行距离测量
 * @endif 
 */
void Ultrasonic_Init(void);

/**
 * @if Eng
 * @brief Gets the measured distance from the ultrasonic sensor 
 * @param None
 * @return Distance in centimeters (double precision)
 * @result Distance measurement is calculated and returned 
 * @else 
 * @brief 获取超声波传感器测量的距离 
 * @param 无 
 * @return 距离值(厘米，双精度浮点)
 * @result 计算并返回距离测量值
 * @endif 
 */
double UltrasonicGetLength(void);

/**
 * @if Eng
 * @brief Starts the timer for ultrasonic echo measurement 
 * @param None
 * @result Timer is configured and started for echo pulse timing
 * @else
 * @brief 启动超声波回波测量定时器 
 * @param 无 
 * @result 定时器配置并启动用于回波脉冲计时 
 * @endif 
 */
void OpenTimerForHc(void);

/**
 * @if Eng
 * @brief Stops the timer for ultrasonic echo measurement
 * @param None 
 * @result Timer is stopped and resources are released 
 * @else 
 * @brief 停止超声波回波测量定时器 
 * @param 无 
 * @result 定时器停止并释放资源
 * @endif 
 */
void CloseTimerForHc(void); 

/**
 * @if Eng 
 * @brief Gets the echo timer value from ultrasonic measurement 
 * @param None
 * @return Timer count value corresponding to echo pulse width 
 * @result Echo duration in timer counts is returned 
 * @else 
 * @brief 获取超声波测量的回波定时器值
 * @param 无
 * @return 与回波脉冲宽度对应的定时器计数值
 * @result 返回以定时器计数为单位的回波持续时间
 * @endif 
 */
uint32_t GetEchoTimer(void);

#endif 

